package cn.exrick.xboot.modules.AppUtils.controller;

import cn.exrick.xboot.base.XbootBaseController;
import cn.exrick.xboot.common.utils.PageUtil;
import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.PageVo;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.common.vo.SearchVo;
import cn.exrick.xboot.modules.AppUtils.entity.AppAutoUpdate;
import cn.exrick.xboot.modules.AppUtils.service.AppAutoUpdateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author jiuqi
 */
@Slf4j
@RestController
@Api(description = "AppAutoUpdate管理接口")
@RequestMapping("/xboot/appAutoUpdate")
@Transactional
public class AppAutoUpdateController extends XbootBaseController<AppAutoUpdate, String> {

    @Autowired
    private AppAutoUpdateService appAutoUpdateService;

    @Override
    public AppAutoUpdateService getService() {
        return appAutoUpdateService;
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<AppAutoUpdate>> getByCondition(@ModelAttribute AppAutoUpdate appAutoUpdate,
                                                            @ModelAttribute SearchVo searchVo,
                                                            @ModelAttribute PageVo pageVo){

        Page<AppAutoUpdate> page = appAutoUpdateService.findByCondition(appAutoUpdate, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<AppAutoUpdate>>().setData(page);
    }

    @RequestMapping(value = "/getByType", method = RequestMethod.GET)
    @ApiOperation(value = "通过类型获取")
    public Result<AppAutoUpdate> getByType(AppAutoUpdate appAutoUpdate){

        AppAutoUpdate type = appAutoUpdateService.findByType(appAutoUpdate.getType());
        return new ResultUtil<AppAutoUpdate>().setData(type);
    }
}
